public class Solution121 {
    public int maxProfit(int[] prices) {
        int res = 0;
        int low = prices[0];
        for (int price : prices) {
            if (price < low) {
                low = price;
            } else {
                res = Math.max(res, price - low);
            }
        }
        return res;
    }
}
